package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class RegDemo {
    public static void main(String[] args) throws Exception {
        WeiBo weiBo = InputUtil.getInputObject(new WeiBo(),"欢迎注册");
        System.out.println(weiBo);

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3066/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",//数据库的地址(格式大致相同，但是不同数据库也有差别)
                "root",
                "root"
        );
        Statement statement = connection.createStatement();
        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                     "VALUES('"+weiBo.getUsername()+"','"+weiBo.getPassword()+"','"+weiBo.getNickname()+"',"+weiBo.getAge()+")";
        System.out.println(sql);
        statement.executeUpdate(sql);
        System.out.println("注册成功!");
        connection.close();
    }
}
